package cn.bdqn.tangcc.user.controller;

import cn.bdqn.tangcc.entity.Tbuser;
import cn.bdqn.tangcc.user.services.UserServices;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

import javax.inject.Inject;
import javax.servlet.http.HttpSession;

/**
 * Created by Administrator on 2016/5/29.
 */
@Controller
public class LoginController {
    @Inject
    private UserServices userServices;

    @RequestMapping(value = {"/loginController"},method = RequestMethod.POST)
    public String login(Tbuser users, Model model, HttpSession session, Tbuser login){
        String forward="";
        Tbuser u = this.userServices.login(users);
        if (u != null) {
            session.setAttribute("users",u);
            forward = "main/main";

        } else {
            model.addAttribute("msg", "对不起，用户名或者密码错误!");
            forward = InternalResourceViewResolver.FORWARD_URL_PREFIX+"index.jsp";
        }
        return forward;
    }
}
